const Basic_url = 'http://218.60.145.61:8081/api/'

export const myRequest = (options)=>{
	return new Promise((resolve,reject)=>{
		options.data = options.data || null
		let method = options.method || 'GET'
		// console.log(options.data)
		const tokenValue = uni.getStorageSync('token')
		const roleId = uni.getStorageSync('roleId')
		if(tokenValue && !roleId) {
			uni.$emit('getInfo')
		}
		uni.request({
			url: Basic_url + options.url,
			method: options.method || 'GET',
			timeout: options.timeout || 300000,
			data: options.data,
			header: {
				"token": tokenValue || {}
			},
			success:(res)=>{
				if(res.data.code == 201 && res.data.message == '需要登录') {
					uni.$emit('doLogin')
					return false
				}
				resolve(res)
			},
			fail:(err)=>{
				console.log(err)
				uni.showToast({
					title: err.message || '请求失败',
					icon:'none'
				})
				reject(err)
			}
		})
	})
}

export default Basic_url